package com.baselibrary.utils;

import static com.baselibrary.utils.ScreenUtils.getScreenWidth;

import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * @author:hanke 2022/3/31
 * desc:
 */
public class ImageUtils {
    /**
     * 根据图片比例调整imageView宽高®
     */
    public static void setImageViewSize(ImageView imageView, boolean isHorizon) {
        ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
        int width = (int) (getScreenWidth(imageView.getContext()) / 2f - ScreenUtils.dpToPx(10));
        layoutParams.height = (int) width * 24 / 19;
        imageView.setLayoutParams(layoutParams);
    }

    public static void setImageViewSize(ImageView imageView) {
        ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
        int width = (getScreenWidth(imageView.getContext()) - ScreenUtils.dpToPx(28));
        layoutParams.height = (int) width * 3 / 4;
        imageView.setLayoutParams(layoutParams);
    }

    public static void addMask(int width, ImageView imageView, ImageView mask, TextView content, TextView joinNumber) {
        int scaledH = ScreenUtils.dpToPx(80);
        int scaledW = width;
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(scaledW, scaledH);
        imageView.setLayoutParams(lp);
        mask.setLayoutParams(lp);
        content.setLayoutParams(lp);
        joinNumber.setLayoutParams(lp);
    }

}
